package com.hunt.testspringboot.web;

import com.hunt.testspringboot.bean.Book;
import com.hunt.testspringboot.bean.User;
import com.hunt.testspringboot.service.UserService;
import com.xiaoleilu.hutool.Hutool;
import com.xiaoleilu.hutool.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

@Controller
@RequestMapping("/page")
public class PageController {

    @Autowired
    private Book book;

    @Autowired
    private UserService userService;

    /**
     * 测试页面
     */
    @RequestMapping("/test")
    public String testpage(Model model){
        model.addAttribute(book);
        return "test";
    }

    @RequestMapping("/adduser")
    public String addUser(){

        return "adduser";
    }

    @RequestMapping(value = "/saveuser",method = RequestMethod.POST)
    public void saveuser(User user){
        user.setId(RandomUtil.randomUUID().replace("-",""));
        user.setCrtdate(new Date());
        userService.save(user);

    }
}
